<div class="layui-fluid layui-anim website-anim-up" id="website-class-assign" lay-title="分配专家">
    <div class="layui-row layui-col-space8 website-container">
        <div class="layui-col-md10 layui-col-sm10 layui-col-xs10">
            <input type="hidden" id="operation" autocomplete="off" class="layui-input" data-th-value="${operation}"/>
            <input type="hidden" id="topicId" autocomplete="off" class="layui-input" data-th-value="${topicId}"/>
            <input type="hidden" id="topicClassifyCode" autocomplete="off" class="layui-input" data-th-value="${topicClassifyCode}"/>
            <div class="layui-card" id="client-class-expert">
                <div class="layui-card-header">专家组成员信息</div>
                <div class="layui-card-body website-table-full">
                    <div id = "showTipExpert"></div>
                    <table id="expertTable" lay-filter="expertTable"
                           lay-data="{id: 'expertTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarExpertSave">
    {{#
    var operation=layui.jquery("#operation").val();
    }}
    {{#  if(operation === 'showButton'){ }}
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getAllData">确认</button>
    </div>
    {{#  } }}
</script>
<!--表格中的操作栏-->
<script type="text/html" id="expert-option">
    {{#
    var operation=layui.jquery("#operation").val();
    }}
    {{#  if(operation === 'showButton'){ }}
    <a lay-event="modify" class="website-green" shiro:hasPermission="review:assignExpert">修改</a>
    {{#  } }}
    <a lay-event="detail" class="website-green">详情</a>
</script>
<script type="text/html" id="expert-class">
    {{#
    var dict=layui.dict.getByCode(d.subjectTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="expert-district">
    {{#
    var dict=layui.dict.getByCode(d.districtTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="expert-feature">
    {{#
    var dict=layui.dict.getByCode(d.featureTypeCode);
    }}
    {{#  if(dict){ }}
    <span>{{ dict.name }}</span>
    {{#  } }}
</script>
<script type="text/html" id="groupNo-class">
    <span>第{{ d.groupNo }}组</span>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'website', 'treeSelect', 'dict'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            website = layui.website,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            $view = $('#website-class-assign'),
            $expertView = $('#client-class-expert'), expertTableIns;
        // 重新渲染 form否则不会显示下拉框
        form.render();
        initExpertTable();
        function initExpertTable() {
            expertTableIns = website.table.init({
                elem: $expertView.find('table'),
                toolbar: '#toolbarExpertSave',
                defaultToolbar:[],
                id: 'expertTable',
                // url: ctx + 'review/'+ $("#topicId").val() +'/experts/',
                cols: [[
                    { type: 'numbers', title: '序号'},
                    {field: 'groupNo', title: '组号', templet: '#groupNo-class'},
                    {field: 'name', title: '姓名', minWidth: 80},
                    {title: '学科', templet: '#expert-class'},
                    {field: 'mobile', title: '联系电话'},
                    {field: 'company', title: '工作单位'},
                    {title: '京内/京外', templet: '#expert-district'},
                    {title: '理论/实务', templet: '#expert-feature'},
                    {title: '操作',  toolbar: '#expert-option', minWidth: 140}
                ]],
                data:[]
            });
            website.get(ctx + 'review/'+ $("#topicId").val() +'/experts/', null, function (result) {
                if(result.data && result.data.list) {
                    table.reload('expertTable', {data: result.data.list});
                    if(result.data.list.length < 1){
                        $("#showTipExpert").html("<span style='color:red;font-weight:bold'>注：该选题没有评审专家，请点击确认！</span>");
                    }
                }
            });
        }
        /**
         * table操作栏的按钮监听事件
         **/
        table.on('tool(expertTable)', function (obj) {
            var data = obj.data,
                    layEvent = obj.event;
            debugger
            if (layEvent === 'modify') {
                website.modal.view('选择专家', 'biz/review/expertGroup/' + data.expertGroupId, {
                    area: $(window).width() <= 750 ? '95%' : '80%'
                });
            } else if(layEvent === 'detail'){
                website.modal.view('专家评审详情', 'biz/review/expertDetails/' + data.expertGroupId, {
                    area: $(window).width() <= 750 ? '95%' : '80%'
                });
            }
        });

/*        /!**
         * table操作栏的按钮监听事件
         **!/
        table.on('tool(expertTable)', function (obj) {
            var data = obj.data,
                    layEvent = obj.event;
            if (layEvent === 'modify') {
                website.modal.view('选择专家', 'biz/review/'+ $("#topicId").val() +'/experts/' + data.expertId, {
                    area: $(window).width() <= 750 ? '95%' : '80%'
                });
            } else if(layEvent === 'detail'){
                website.modal.view('专家信息', 'biz/review/'+ $("#topicId").val() +'/experts/' + data.expertId, {
                    area: $(window).width() <= 750 ? '95%' : '80%'
                });
            }
        });*/


        table.on('toolbar(expertTable)', function(obj){
            switch(obj.event){
                case 'getAllData':
                    var data = table.cache[obj.config.id]; //获取数据表格中所有数据
                    website.modal.confirm('专家确认', '确认后不能再修改本选题专家分配，是否确认分配的专家不再修改？', function () {
                        website.ajaxPost(ctx + 'reviews/' + $("#topicId").val() + '/experts/' + $("#topicClassifyCode").val() + '/confirm',JSON.stringify(data), function (data) {
                            debugger
                            website.alert.success(data.data);
                            var currentUrl = window.location.hash.replace('#', '');
                            website.view.tab.del(currentUrl);
                        });
                    });
                    break;
                case 'addData':
                    break;
            };

        });
    })


</script>